package invest.pojo;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.util.Set;

/**
 * @author zhichao.ni
 * 2021/5/17
 **/
public class XueqiuCookie {
	private static String cookie=null;
	private static WebDriver driver=null;
	static {
		if (System.getProperty("os.name").startsWith("Windows")) {
			System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
		} else {
			System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
		}
		ChromeOptions options=new ChromeOptions();
		options.addArguments("--headless");
		options.addArguments("--no-sandbox");
		options.addArguments("--disable-gpu");
		options.addArguments("--disable-dev-shm-usage");
		driver= new ChromeDriver(options);
	}

	public static String getXueqiuCookie() {
		if (cookie == null) {
			setXueqiuCookie();
			return cookie;
		} else {
			return cookie;
		}
	}
	public static void setXueqiuCookie() {
		WebDriver driver = XueqiuCookie.driver;
		driver.get("https://xueqiu.com/hq#exchange=CN&firstName=1&secondName=1_0");
		WebDriver.Options manage = driver.manage();
		Set<org.openqa.selenium.Cookie> cookies = manage.getCookies();
		String cookie = "";
		for (org.openqa.selenium.Cookie c : cookies
		) {
			cookie=cookie+c.getName();
			cookie = cookie + "=" + c.getValue() + ";";
		}
		XueqiuCookie.cookie = cookie;

	}
	public static void driverClose() {
		driver.close();

	}



}
